import request from '@/utils/request'

export interface MaterialDTO {
  materialId?: string
  materialCode: string
  materialName: string
  categoryId?: string
  uomId: string
  enableBatch?: number
  enableSerial?: number
  barcode?: string
  taxRate?: number
  status?: number
  remark?: string
}

export function pageMaterial(params: { pageNum: number; pageSize: number; materialCode?: string; materialName?: string; status?: number; enableBatch?: number; enableSerial?: number; startTime?: string; endTime?: string }) {
  return request({ url: '/erp/material/page', method: 'get', params })
}

export function getMaterial(id: string) {
  return request({ url: `/erp/material/${id}`, method: 'get' })
}

export function createMaterial(data: MaterialDTO) {
  return request({ url: '/erp/material', method: 'post', data })
}

export function updateMaterial(id: string, data: MaterialDTO) {
  return request({ url: `/erp/material/${String(id)}`, method: 'put', data })
}

export function deleteMaterial(id: string) {
  return request({ url: `/erp/material/${String(id)}`, method: 'delete' })
}

export function deleteMaterialBatch(ids: string[]) {
  return request({ url: '/erp/material/batch-delete', method: 'post', data: ids })
}

export function exportMaterial(params: { materialCode?: string; materialName?: string; status?: number; enableBatch?: number; enableSerial?: number; startTime?: string; endTime?: string; ids?: string[] }) {
  return request({ url: '/erp/material/export', method: 'get', params, responseType: 'blob' })
}

export function getMaterialIds(params: { materialCode?: string; materialName?: string; status?: number; enableBatch?: number; enableSerial?: number; startTime?: string; endTime?: string }) {
  return request({ url: '/erp/material/ids', method: 'get', params })
}

export function listMaterial(params: { pageNum: number; pageSize: number }) {
  return request({ url: '/erp/material/page', method: 'get', params })
}


